package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovol.farm.base.service.common.ResultResponse;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>farm/base/v1.0/${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} service;

    @Operation(summary = "添加某一条数据")
    @PostMapping("/doInsert")
    public ResultResponse doInsert(@RequestBody ${entity} bean) {
        return service.doInsert(bean);
    }

    @Operation(summary = "删除某一条id数据")
    @GetMapping("/doDeleteById")
    public ResultResponse doDeleteById(@Parameter(name = "id", description = "唯一标识id", required = true) String id) {
        return service.doDeleteById(id);
    }

    @Operation(summary = "更新某一条数据")
    @PostMapping("/doUpdate")
    public ResultResponse doUpdate(@RequestBody ${entity} bean) {
        return service.doUpdate(bean);
    }

    @Operation(summary = "获取某一条id数据")
    @GetMapping("/getItemById")
    public ResultResponse getItemById(@Parameter(name = "id", description = "唯一标识id", required = true) String id) {
        return service.getItemById(id);
    }

    @Operation(summary = "分页与and条件过滤")
    @PostMapping(value = "/pageConditionAnd")
    public ResultResponse pageConditionAnd(@RequestBody PageConditionDTO pageConditionDTO) {
         QueryWrapper queryWrapper = new QueryWrapper();
         List<ConditionDTO>conditions = pageConditionDTO.getConditions();
         if(conditions!=null && conditions.size()>0){
             queryWrapper = SearchUtil.parseAndSql(conditions);
         }
         return service.pageCondition(pageConditionDTO.getPage(),pageConditionDTO.getLimit(),queryWrapper);
    }

    @Operation(summary = "分页与Or条件过滤")
    @PostMapping(value = "/pageConditionOr")
    public ResultResponse pageConditionOr(@RequestBody PageConditionDTO pageConditionDTO) {
        QueryWrapper queryWrapper = new QueryWrapper();
        List<ConditionDTO>conditions = pageConditionDTO.getConditions();
        if(conditions!=null && conditions.size()>0){
             queryWrapper = SearchUtil.parseOrSql(conditions);
        }
        return service.pageCondition(pageConditionDTO.getPage(),pageConditionDTO.getLimit(),queryWrapper);
    }

     @Operation(summary = "多字段and查询")
     @PostMapping(value = "/customQuery")
     public ResultResponse customQuery(@RequestBody List<ConditionDTO>conditions) {
          QueryWrapper queryWrapper = SearchUtil.parseAndSql(conditions);
          return service.customQuery(queryWrapper);
     }

     @Operation(summary = "多字段OR查询")
     @PostMapping(value = "/orQuery")
     public ResultResponse orQuery(@RequestBody List<ConditionDTO>conditions) {
           QueryWrapper queryWrapper = SearchUtil.parseOrSql(conditions);
           return service.customQuery(queryWrapper);
     }

     @Operation(summary = "多边形查询")
     @GetMapping("/queryByPolygon")
     public ResultResponse queryByPolygon(@Parameter(name = "quereyGeom", description = "查询多边形", required = true) String quereyGeom)
     {
         return service.queryByPolygon(quereyGeom);
     }
}
</#if>
